<!DOCTYPE html><html><head>
<title>multiplexer - One-to-many communication with sockets.</title>
<style type="text/css"><!--
    HTML {
	background: 	#FFFFFF;
	color: 		black;
    }
    BODY {
	background: 	#FFFFFF;
	color:	 	black;
    }
    DIV.doctools {
	margin-left:	10%;
	margin-right:	10%;
    }
    DIV.doctools H1,DIV.doctools H2 {
	margin-left:	-5%;
    }
    H1, H2, H3, H4 {
	margin-top: 	1em;
	font-family:	sans-serif;
	font-size:	large;
	color:		#005A9C;
	background: 	transparent;
	text-align:		left;
    }
    H1.doctools_title {
	text-align: center;
    }
    UL,OL {
	margin-right: 0em;
	margin-top: 3pt;
	margin-bottom: 3pt;
    }
    UL LI {
	list-style: disc;
    }
    OL LI {
	list-style: decimal;
    }
    DT {
	padding-top: 	1ex;
    }
    UL.doctools_toc,UL.doctools_toc UL, UL.doctools_toc UL UL {
	font:		normal 12pt/14pt sans-serif;
	list-style:	none;
    }
    LI.doctools_section, LI.doctools_subsection {
	list-style: 	none;
	margin-left: 	0em;
	text-indent:	0em;
	padding: 	0em;
    }
    PRE {
	display: 	block;
	font-family:	monospace;
	white-space:	pre;
	margin:		0%;
	padding-top:	0.5ex;
	padding-bottom:	0.5ex;
	padding-left:	1ex;
	padding-right:	1ex;
	width:		100%;
    }
    PRE.doctools_example {
	color: 		black;
	background: 	#f5dcb3;
	border:		1px solid black;
    }
    UL.doctools_requirements LI, UL.doctools_syntax LI {
	list-style: 	none;
	margin-left: 	0em;
	text-indent:	0em;
	padding:	0em;
    }
    DIV.doctools_synopsis {
	color: 		black;
	background: 	#80ffff;
	border:		1px solid black;
	font-family:	serif;
	margin-top: 	1em;
	margin-bottom: 	1em;
    }
    UL.doctools_syntax {
	margin-top: 	1em;
	border-top:	1px solid black;
    }
    UL.doctools_requirements {
	margin-bottom: 	1em;
	border-bottom:	1px solid black;
    }
--></style>
</head>
<!-- Generated from file 'multiplexer.man' by tcllib/doctools with format 'html'
   -->
<!-- multiplexer.n
   -->
<body><hr> [
   <a href="../../../../../../../../home">Tcllib Home</a>
&#124; <a href="../../../../toc.html">Main Table Of Contents</a>
&#124; <a href="../../../toc.html">Table Of Contents</a>
&#124; <a href="../../../../index.html">Keyword Index</a>
&#124; <a href="../../../../toc0.html">Categories</a>
&#124; <a href="../../../../toc1.html">Modules</a>
&#124; <a href="../../../../toc2.html">Applications</a>
 ] <hr>
<div class="doctools">
<h1 class="doctools_title">multiplexer(n) 0.2 tcllib &quot;One-to-many communication with sockets.&quot;</h1>
<div id="name" class="doctools_section"><h2><a name="name">Name</a></h2>
<p>multiplexer - One-to-many communication with sockets.</p>
</div>
<div id="toc" class="doctools_section"><h2><a name="toc">Table Of Contents</a></h2>
<ul class="doctools_toc">
<li class="doctools_section"><a href="#toc">Table Of Contents</a></li>
<li class="doctools_section"><a href="#synopsis">Synopsis</a></li>
<li class="doctools_section"><a href="#section1">Description</a></li>
<li class="doctools_section"><a href="#section2">Bugs, Ideas, Feedback</a></li>
<li class="doctools_section"><a href="#keywords">Keywords</a></li>
<li class="doctools_section"><a href="#category">Category</a></li>
</ul>
</div>
<div id="synopsis" class="doctools_section"><h2><a name="synopsis">Synopsis</a></h2>
<div class="doctools_synopsis">
<ul class="doctools_requirements">
<li>package require <b class="pkgname">Tcl 8.2</b></li>
<li>package require <b class="pkgname">logger</b></li>
<li>package require <b class="pkgname">multiplexer <span class="opt">?0.2?</span></b></li>
</ul>
<ul class="doctools_syntax">
<li><a href="#1"><b class="cmd">::multiplexer::create</b></a></li>
<li><a href="#2"><b class="cmd">${multiplexer_instance}::Init</b> <i class="arg">port</i></a></li>
<li><a href="#3"><b class="cmd">${multiplexer_instance}::Config</b> <i class="arg">key</i> <i class="arg">value</i></a></li>
<li><a href="#4"><b class="cmd">${multiplexer_instance}::AddFilter</b> <i class="arg">cmdprefix</i></a></li>
<li><a href="#5"><b class="cmd">cmdprefix</b> <i class="arg">data</i> <i class="arg">chan</i> <i class="arg">clientaddress</i> <i class="arg">clientport</i></a></li>
<li><a href="#6"><b class="cmd">${multiplexer_instance}::AddAccessFilter</b> <i class="arg">cmdprefix</i></a></li>
<li><a href="#7"><b class="cmd">cmdprefix</b> <i class="arg">chan</i> <i class="arg">clientaddress</i> <i class="arg">clientport</i></a></li>
<li><a href="#8"><b class="cmd">${multiplexer_instance}::AddExitFilter</b> <i class="arg">cmdprefix</i></a></li>
<li><a href="#9"><b class="cmd">cmdprefix</b> <i class="arg">chan</i> <i class="arg">clientaddress</i> <i class="arg">clientport</i></a></li>
</ul>
</div>
</div>
<div id="section1" class="doctools_section"><h2><a name="section1">Description</a></h2>
<p>The <b class="package">multiplexer</b> package provides a generic system for one-to-many
communication utilizing sockets.  For example, think of a chat system
where one user sends a message which is then broadcast to all the
other connected users.</p>
<p>It is possible to have different multiplexers running concurrently.</p>
<dl class="doctools_definitions">
<dt><a name="1"><b class="cmd">::multiplexer::create</b></a></dt>
<dd><p>The <b class="cmd">create</b> command creates a new multiplexer 'instance'.  For
example:</p>
<pre class="doctools_example">set mp [::multiplexer::create]</pre>
<p>This instance can then be manipulated like so:</p>
<pre class="doctools_example">${mp}::Init 35100</pre>
</dd>
<dt><a name="2"><b class="cmd">${multiplexer_instance}::Init</b> <i class="arg">port</i></a></dt>
<dd><p>This starts the multiplexer listening on the specified port.</p></dd>
<dt><a name="3"><b class="cmd">${multiplexer_instance}::Config</b> <i class="arg">key</i> <i class="arg">value</i></a></dt>
<dd><p>Use <b class="cmd">Config</b> to configure the multiplexer instance.  Configuration
options currently include:</p>
<dl class="doctools_options">
<dt><b class="option">sendtoorigin</b></dt>
<dd><p>A boolean flag. If <b class="const">true</b>, the sender will receive a copy of the
sent message.  Defaults to <b class="const">false</b>.</p></dd>
<dt><b class="option">debuglevel</b></dt>
<dd><p>Sets the debug level to use for the multiplexer instance, according to
those specified by the <b class="package"><a href="../log/logger.html">logger</a></b> package (debug, info, notice,
warn, error, critical).</p></dd>
</dl></dd>
<dt><a name="4"><b class="cmd">${multiplexer_instance}::AddFilter</b> <i class="arg">cmdprefix</i></a></dt>
<dd><p>Command to add a filter for data that passes through the multiplexer
instance.
The registered <i class="arg">cmdprefix</i> is called when data arrives at a
multiplexer instance. If there is more than one filter command
registered at the instance they will be called in the order of
registristation, and each filter will get the result of the preceding
filter as its argument. The first filter gets the incoming data as its
argument. The result returned by the last filter is the data which
will be broadcast to all clients of the multiplexer instance.
The command prefix is called as</p>
<dl class="doctools_definitions">
<dt><a name="5"><b class="cmd">cmdprefix</b> <i class="arg">data</i> <i class="arg">chan</i> <i class="arg">clientaddress</i> <i class="arg">clientport</i></a></dt>
<dd><p>Takes the incoming <i class="arg">data</i>, modifies it, and returns that as its
result. The last three arguments contain information about the client
which sent the data to filter: The channel connecting us to the
client, its ip-address, and its ip-port.</p></dd>
</dl></dd>
<dt><a name="6"><b class="cmd">${multiplexer_instance}::AddAccessFilter</b> <i class="arg">cmdprefix</i></a></dt>
<dd><p>Command to add an access filter.
The registered <i class="arg">cmdprefix</i> is called when a new client socket
tries to connect to the multixer instance. If there is more than one
access filter command registered at the instance they will be called
in the order of registristation. If any of the called commands returns
<b class="const">-1</b> the access to the multiplexer instance is denied and the
client channel is closed immediately. Any other result grants the
client access to the multiplexer instance.
The command prefix is called as</p>
<dl class="doctools_definitions">
<dt><a name="7"><b class="cmd">cmdprefix</b> <i class="arg">chan</i> <i class="arg">clientaddress</i> <i class="arg">clientport</i></a></dt>
<dd><p>The arguments contain information about the client which tries to
connected to the instance: The channel connecting us to the client,
its ip-address, and its ip-port.</p></dd>
</dl></dd>
<dt><a name="8"><b class="cmd">${multiplexer_instance}::AddExitFilter</b> <i class="arg">cmdprefix</i></a></dt>
<dd><p>Adds filter to be run when client socket generates an EOF condition.
The registered <i class="arg">cmdprefix</i> is called when a client socket of the
multixer signals EOF. If there is more than one exit filter command
registered at the instance they will be called in the order of
registristation. Errors thrown by an exit filter are ignored, but
logged. Any result returned by an exit filter is ignored.
The command prefix is called as</p>
<dl class="doctools_definitions">
<dt><a name="9"><b class="cmd">cmdprefix</b> <i class="arg">chan</i> <i class="arg">clientaddress</i> <i class="arg">clientport</i></a></dt>
<dd><p>The arguments contain information about the client which signaled the
EOF: The channel connecting us to the client, its ip-address, and its
ip-port.</p></dd>
</dl></dd>
</dl>
</div>
<div id="section2" class="doctools_section"><h2><a name="section2">Bugs, Ideas, Feedback</a></h2>
<p>This document, and the package it describes, will undoubtedly contain
bugs and other problems.
Please report such in the category <em>multiplexer</em> of the
<a href="http://core.tcl.tk/tcllib/reportlist">Tcllib Trackers</a>.
Please also report any ideas for enhancements you may have for either
package and/or documentation.</p>
<p>When proposing code changes, please provide <em>unified diffs</em>,
i.e the output of <b class="const">diff -u</b>.</p>
<p>Note further that <em>attachments</em> are strongly preferred over
inlined patches. Attachments can be made by going to the <b class="const">Edit</b>
form of the ticket immediately after its creation, and then using the
left-most button in the secondary navigation bar.</p>
</div>
<div id="keywords" class="doctools_section"><h2><a name="keywords">Keywords</a></h2>
<p><a href="../../../../index.html#chat">chat</a>, <a href="../../../../index.html#multiplexer">multiplexer</a></p>
</div>
<div id="category" class="doctools_section"><h2><a name="category">Category</a></h2>
<p>Programming tools</p>
</div>
</div></body></html>
